package com.longdaji.decoration.ui.register.graduation;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.longdaji.decoration.R;
import com.longdaji.decoration.base.BaseActivity;
import com.longdaji.decoration.bean.Account;
import com.longdaji.decoration.ui.activitiesOfMine.personData.PersonalDataActivity;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class GraduationActivity extends BaseActivity implements GraduationContract.IView {

    @Inject
    GraduationContract.IPresenter mPresenter;
    @BindView(R.id.tv_tool_title)
    TextView tvTitle;
    @BindView(R.id.tv_finish)
    TextView tvFinish;
    @BindView(R.id.iv_graduation_no)
    ImageView ivGraduationNo;
    @BindView(R.id.iv_graduation_yes)
    ImageView ivGraduationYes;

    private Bundle bundle;
    private boolean isGraduated = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_graduation);
        setUnBinder(ButterKnife.bind(this));

        if (mPresenter != null)
            mPresenter.setView(this);
        tvTitle.setText("个人信息");
        tvFinish.setText("下一步");
        bundle = getIntent().getExtras();
        initView();
    }

    private void initView() {
        Account.getInstance().setIsGraduate(1);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mPresenter != null)
            mPresenter.detachView();
    }

    @OnClick({R.id.rl_tool_back, R.id.tv_finish, R.id.rl_graduation_no, R.id.rl_graduation_yes})
    void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_tool_back:
                finish();
                break;
            case R.id.rl_graduation_no:
                showGraduationNo();
                break;
            case R.id.rl_graduation_yes:
                showGraduationYes();
                break;
            case R.id.tv_finish:
                showStepThree();
            default:
                break;
        }
    }

    private void showStepThree() {
        if (isGraduated) {
            bundle.putInt("isGraduate", 1);
        } else {
            bundle.putInt("isGraduate", 0);
        }
        Intent intent = new Intent(this, PersonalDataActivity.class);
        intent.putExtras(bundle);
        startActivity(intent);
    }

    private void showGraduationNo() {
        isGraduated = false;
        ivGraduationNo.setVisibility(View.VISIBLE);
        ivGraduationYes.setVisibility(View.INVISIBLE);

    }

    private void showGraduationYes() {
        isGraduated = true;
        ivGraduationNo.setVisibility(View.INVISIBLE);
        ivGraduationYes.setVisibility(View.VISIBLE);
    }
}
